package com.zpc.myvideoserver.common.security.pojo;

import io.jsonwebtoken.lang.Assert;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @ClassName : AccountUser  //类名
 * @Description : 用户信息实体类  //描述
 * @Author : zpc20 //作者
 * @Date: 2023/11/1  23:26
 */
@Data
public class AccountUser implements UserDetails {

    private Integer userId;
    private String password;
    private  String username;

    private final boolean isAccountNonExpired;
    private final boolean isAccountNotLocked;
    private final boolean isCredentialsNonExpired;
    private final boolean isEnabled;
    private final Collection<? extends GrantedAuthority> authorities;
    public AccountUser(Integer userId, String username, String password, Collection<? extends GrantedAuthority> authorities) {
        this(userId, username, password, true, true, true, true, authorities);
    }

    public AccountUser(Integer userId, String username, String password, boolean isEnabled, boolean isAccountNonExpired, boolean isAccountNotLocked, boolean isCredentialsNonExpired, Collection<? extends GrantedAuthority> authorities) {
        Assert.isTrue(username!=null && !username.isEmpty() &&password!=null,"Cannot pass null");
        this.userId = userId;
        this.username =username;
        this.password =password;
        this.isEnabled = isEnabled;
        this.isAccountNonExpired =isAccountNonExpired;
        this.isAccountNotLocked = isAccountNotLocked;
        this.isCredentialsNonExpired = isCredentialsNonExpired;
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return this.isAccountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.isAccountNotLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return this.isCredentialsNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return this.isEnabled;
    }
}
